/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vasthu.core.service;

import com.vasthu.api.dao.FunctionDAO;
import com.vasthu.api.domain.Function;
import com.vasthu.api.service.FunctionManagerService;
import com.vasthu.core.dao.FunctionDAOImpl;
import com.vasthu.gui.VstTableItemSelectable;
import com.vasthu.utility.VstDBManager;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author moremada
 */
public class FunctionManagerServiceImpl implements FunctionManagerService {

    private FunctionDAO functionDAO;

    public FunctionManagerServiceImpl() {
        functionDAO = new FunctionDAOImpl();
    }

    @Override
    public boolean insertFunction(Function function) {
        if (function == null) {
            return false;
        }
        boolean ok = false;
        ok = functionDAO.insertFunction(function);
        return ok;
    }

    @Override
    public Function getFunctionById(int funcId) {
        Connection conn = VstDBManager.get().getConnection();
        Function fun = functionDAO.getFunctionById(funcId);
        return fun;
    }

    @Override
    public Function getFunctionByName(String funcName) {
        Connection conn = VstDBManager.get().getConnection();
        Function fun = functionDAO.getFunctionByName(funcName);
        return fun;
    }

    @Override
    public boolean deleteFunctionById(int funcId) {
        boolean ok = false;
        ok = functionDAO.deleteFunctionById(funcId);
        return ok;
    }

    @Override
    public List<String> getAllFunctionNames() {
        List<Function> funList = new ArrayList<Function>();
        List<String> funNameList = new ArrayList<String>();
        funList = functionDAO.getAllFunctions();
        for (Function fun : funList) {
            funNameList.add(fun.getFuncName());
        }
        return funNameList;
    }

    @Override
    public List<VstTableItemSelectable> getAllFunctionsForTable() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
